package com.hiof.servercommunication.background.job;

import com.hiof.beans.UserInfo;
import com.hiof.servercommunication.RestFulServiceManager;
import com.hiof.servercommunication.receive.beans.AthleteLocationReceivePacket;
import com.hiof.servercommunication.receive.beans.GeoPoint;
import com.hiof.servercommunication.receive.beans.Packet;
import com.hiof.settings.user.UserConfiguration;
import com.hiof.utility.Utility;

/**
 * Created by IntelliJ IDEA.
 * User: manish
 * Date: 4/1/12
 * Time: 12:28 PM
 * To change this template use File | Settings | File Templates.
 */
public class GetAthleteLatestLocationJob extends AbstractJob {
    @Override
    protected Packet connect2Server() {
        AthleteLocationReceivePacket athleteAthleteLocationPacket = new AthleteLocationReceivePacket();
        int athleteId;
        try {
            UserInfo athleteInfo = UserConfiguration.getInstance().getAthleteWhenUserIsSupport();
            if (athleteInfo != null) {
                athleteId = athleteInfo.getAttendantId();
                GeoPoint latestAthleteLocationInfo = RestFulServiceManager.getInstance().getAthleteLatestLocationInfo(athleteId);

                athleteAthleteLocationPacket.setLat(latestAthleteLocationInfo.getLat());
                athleteAthleteLocationPacket.setLng(latestAthleteLocationInfo.getLng());
                athleteAthleteLocationPacket.setHeight(latestAthleteLocationInfo.getAltitude());
            }
        } catch (Exception e) {
            Utility.error(this.getClass().toString(), e.getMessage());
        }
        return athleteAthleteLocationPacket;
    }
}
